package base

import (
	"math/big"
	"math/rand"
	"strconv"
)

func StringToGwei(numstr string) int64 {
	z, _ := new(big.Int).SetString(numstr, 10)
	if z == nil {
		return 0
	}
	z.Div(z, big.NewInt(1000000000))
	return z.Int64()
}

// wei to Gwei
func ToGwei(z *big.Int) int64 {
	if z == nil {
		return 0
	}
	z.Div(z, big.NewInt(1000000000))
	return z.Int64()
}

func RandDigitCode(l int) string {
	var out string
	for i := 0; i < l; i++ {
		a := rand.Intn(10)
		out += strconv.Itoa(a)
	}
	return out
}
